const express = require('express');
const router = express.Router();

const {
  Worker, isMainThread, parentPort, workerData, threadId
} = require('worker_threads');

/* GET home page. */
router.get('/', (req, res, next) => {
  res.render('index', { title: 'Express' });
});

router.get('/hello', (req, res) => {
  res.send({
    status: 0,
    message: 'success',
    threadId,
    isMainThread
  });
});

router.get('/world', (req, res) => {
  res.send({
    status: 0,
    message: 'success'
  });
});

router.get('/sleep', (req, res) => {
  const startTime = new Date().getTime();
  const duration = 10 * 1000;
  while (new Date().getTime() < startTime + duration) {}

  res.send({
    status: 0,
    message: 'success'
  });
});

module.exports = router;
